/**
 * 2024.2.17 第十三课 String+异常
 */
import java.util.Scanner;
public class Test {
    public  boolean isNumOrCharacter(char ch) {
        if(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z') {
            return true;
        }
        return false;
    }
    public  boolean isPalindrome(String s) {
        s = s.toLowerCase();
        //1. 定义i 和 j
        int i = 0;
        int j = s.length()-1;

        //2、如果i != j
        while (i < j) {
            //3、i要一直走到一个合法的字符那里  有可能i要走很多步
            while (i < j && !isNumOrCharacter(s.charAt(i))) {
                i++;
            }
            //4、j要一直走到一个合法的字符那里  有可能j要走很多步
            while (i < j &&!isNumOrCharacter(s.charAt(j))) {
                j--;
            }
            //5. 对应下标字符一样 i++; j--;
            if(s.charAt(i) == s.charAt(j)) {
                i++;
                j--;
            }else {
                //6、对应下标字符不一样
                return false;
            }
        }
        return true;
    }
    public int firstUniqChar(String s) {
        int[] count = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            count[ch-'a']++;//计数的
        }
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(count[ch-'a'] == 1){
                return i;
            }
        }
        return -1;
    }
    public static void main5(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String  s = in.nextLine();
            int index = s.lastIndexOf(' ');
            String str = s.substring(index+1);
            System.out.print(str.length());
        }

        StringBuilder stringBuilder = new StringBuilder("hello");

        stringBuilder.reverse();

        System.out.println(stringBuilder);
    }
    public static void main1(String[] args) {
        String str = "hello";
        str = str + "abc";//helloabc
        System.out.println(str);
    }
    public static void main2(String[] args) {
        String str = "hello";
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(str);
        stringBuilder.append("abc");
        str = stringBuilder.toString();
        System.out.println(str);
    }
    public static void main3(String[] args) {

        long start = System.currentTimeMillis();
        String s = "";
        for(int i = 0; i < 10000; ++i){
            s += i;
        }
        long end = System.currentTimeMillis();
        System.out.println("String: "+ (end - start));

        start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 10000; ++i){
            sbf.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println("StringBuffer: "+ (end - start));

        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 10000; ++i){
            sbd.append(i);
        }

        end = System.currentTimeMillis();
        System.out.println("StringBuilder: "+ (end - start));
    }
}
